﻿using MediatR;
using ERPSystem.Common.DTO;
using ERPSystem.Common.Domains.WarehouseCommon;
using ERPSystem.Common.Infrastructure.IRepository;
using ERPSystem.Common.Domains.UserCommon;

namespace BasicInformationCommon.API.BasicInformationCommons.Employeees
{
    public class EmployeeQueryHandler : IRequestHandler<EmployeeQueryCommand, Result>
    {
        private readonly IBaseRepository<Employee> _employeeRepository;

        public EmployeeQueryHandler(IBaseRepository<Employee> employeeRepository)
        {
            _employeeRepository = employeeRepository;
        }
        /// <summary>
        /// 查询用户信息业务逻辑
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Result> Handle(EmployeeQueryCommand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            try
            {
                var employeeList = await (await _employeeRepository.GetAll()).ToListAsync();
                result.Data = employeeList;

            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
